package com.freemyleft.left.left_app.mian.index.my.base_setting.certification.dialog;

import android.content.Context;
import android.graphics.Color;


import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.freemyleft.left.left_app.R;
import com.freemyleft.left.zapp.delegates.LeftDelegate;
import com.freemyleft.left.zapp.ui.dialog.MyPhoneDiaLog;
import com.freemyleft.left.zapp.util.callback.CallbackManager;
import com.freemyleft.left.zapp.util.callback.CallbackType;
import com.freemyleft.left.zapp.util.callback.IGlobalCallback;

public class AcademicDiaLog extends MyPhoneDiaLog {
    LeftDelegate DELEGATE;

    public AcademicDiaLog(Context context, LeftDelegate DELEGATE) {
        super(context);
        this.DELEGATE = DELEGATE;
    }
    View bg;
    ImageView dialog_imag_1, dialog_imag_2, dialog_imag_3, dialog_up;
    TextView dialog_text1, dialog_text2, dialog_text3;
    String text1, text2, text3;
    onText1 onText1;
    onText2 onText2;
    onText3 onText3;


    public void setText1(String str, onText1 ontext1) {
        if (str != null) {
            text1 = str;
        }
        this.onText1 = ontext1;
    }

    public void setText2(String str, onText2 ontext2) {
        if (str != null) {
            text2 = str;
        }
        this.onText2 = ontext2;
    }

    public void setText3(String str, onText3 ontext3) {
        if (str != null) {
            text3 = str;
        }
        this.onText3 = ontext3;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_certification);
        //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //一定要在setContentView之后调用，否则无效
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        //按空白处不能取消动画
        setCanceledOnTouchOutside(true);
        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();


    }



    private void initView() {
        bg=findViewById(R.id.bg);
        dialog_imag_1 = findViewById(R.id.dialog_imag_1);
        dialog_imag_2 = findViewById(R.id.dialog_imag_2);
        dialog_imag_3 = findViewById(R.id.dialog_imag_3);
        dialog_text1 = findViewById(R.id.dialog_text1);
        dialog_text2 = findViewById(R.id.dialog_text2);
        dialog_text3 = findViewById(R.id.dialog_text3);
        dialog_up = findViewById(R.id.dialog_up);

    }

    private void initData() {
        if (text1!=null){
            dialog_text1.setText(text1);
        }
        if (text2!=null){
            dialog_text2.setText(text2);
        }
        if (text3!=null){
            dialog_text3.setText(text3);
        }


    }

    private void initEvent() {
        dialog_imag_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DELEGATE.startCameraWithCheck();
                CallbackManager.getInstance().addCallback(CallbackType.ON_CROP, new IGlobalCallback<Uri>() {

                    @Override
                    public void executeCallback(@Nullable Uri args) {
                        Glide.with(getContext())
                                .load(args.getPath()).into(dialog_imag_1);
                    }
                });
            }

        });
        dialog_imag_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DELEGATE.startCameraWithCheck();
                CallbackManager.getInstance().addCallback(CallbackType.ON_CROP, new IGlobalCallback<Uri>() {

                    @Override
                    public void executeCallback(@Nullable Uri args) {
                        Glide.with(getContext())
                                .load(args.getPath()).into(dialog_imag_2);
                    }
                });
            }
        });
        dialog_imag_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DELEGATE.startCameraWithCheck();
                CallbackManager.getInstance().addCallback(CallbackType.ON_CROP, new IGlobalCallback<Uri>() {

                    @Override
                    public void executeCallback(@Nullable Uri args) {
                        Glide.with(getContext())
                                .load(args.getPath()).into(dialog_imag_3);
                    }
                });

            }
        });
        dialog_up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getContext(), "上传照片", Toast.LENGTH_SHORT).show();
                dismiss();
            }
        });
        bg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

    }

    public interface onText1 {
        public void onText1Click();
    }

    public interface onText2 {
        public void onText2Click();
    }

    public interface onText3 {
        public void onText3Click();
    }



    public interface onUp {
        public void onupClick();
    }


}
